package com.bojx.cms.service;

import java.util.List;

import com.bojx.cms.dao.AuthDao;
import com.jfinal.plugin.activerecord.Record;

public class AuthService {
	private static AuthDao authDao=new AuthDao();
	
	public List<Record> findFirstPerms(){
		return authDao.queryPerms(0);
	}

	public List<Record> findPerms() {
		List<Record> parentNodes=findParentNodes();
		for(Record parentNode:parentNodes){
			long parentId=parentNode.getLong("id");
		    List<Record> childrenNodes=findChildrenNodes(parentId);
		    parentNode.set("children", childrenNodes);
		}
		return parentNodes;
	}
	
	private List<Record> findChildrenNodes(long parentId) {
		
		return authDao.queryPerms(parentId);
	}

	private List<Record> findParentNodes(){
		return authDao.queryPerms(0);
	}
}
